
/**   
*    
* 项目名称：a_yongan   
* 类名称：CommonFilter   
* 类描述：   
* 创建人：liubo   
* 创建时间：2018年9月4日 下午8:10:39    
* 修改时间：2018年9月4日 下午8:10:39   
* 修改备注：   
* @version    
*    
*/
package com.yongan.filter;

import java.io.IOException;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author liubo
 *
 */
public class CommonFilter extends HttpFilter {

	
	@Override
	public void doFilter(HttpServletRequest request,HttpServletResponse response, FilterChain filterChain)
			throws IOException, ServletException {
		String username = (String) request.getSession().getAttribute("userid");
		
		String requestUri = request.getRequestURI();
        String contextPath = request.getContextPath();
		String url = requestUri.substring(contextPath.length());	
		
		if ("/vcode".equals(url) | url.contains("mystyle") | url.contains("dologin")) {
            filterChain.doFilter(request, response);
            return;
		}
        if (username == null) {
            request.getRequestDispatcher("/").forward(request, response);
        } else{
            filterChain.doFilter(request, response);
    	}
		
	}

}
